<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"/>
    <title>修改密码 - 光年(Light Year Admin)后台管理系统模板</title>
    <link rel="icon" href="favicon.ico" type="image/ico">
    <meta name="keywords" content="LightYear,光年,后台模板,后台管理系统,光年HTML模板">
    <meta name="description" content="LightYear是一个基于Bootstrap v3.3.7的后台管理系统的HTML模板。">
    <meta name="author" content="yinqi">
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <link href="css/materialdesignicons.min.css" rel="stylesheet">
    <link href="css/style.min.css" rel="stylesheet">
    <#include "../../resource.ftl" />
</head>

<body>
<div class="container-fluid p-t-15">

    <div class="row">
        <div class="col-lg-12">
            <div class="card">
                <div class="card-body">

                    <form method="post" action="#!" class="site-form">
                        <div class="form-group">
                            <label for="old-password">旧密码</label>
                            <input type="password" class="form-control" name="oldPassword" id="oldPassword"
                                   placeholder="输入账号的原登录密码">
                        </div>
                        <div class="form-group">
                            <label for="new-password">新密码</label>
                            <input type="password" class="form-control" name="newPassword" id="newPassword"
                                   placeholder="输入新的密码">
                        </div>
                        <div class="form-group">
                            <label for="confirm-password">确认新密码</label>
                            <input type="password" class="form-control" name="confirmPassword" id="confirmPassword"
                                   placeholder="请输入确认密码">
                        </div>
                        <button type="submit" class="btn btn-primary">修改密码</button>
                    </form>

                </div>
            </div>
        </div>

    </div>

</div>

<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/bootstrap.min.js"></script>
<script type="text/javascript" src="js/main.min.js"></script>
<script type="text/javascript">
    (function ($) {
        $.fn.serializeFormJSON = function () {
            var o = {};
            var a = this.serializeArray();
            $.each(a, function () {
                if (o[this.name]) {
                    if (!o[this.name].push) {
                        o[this.name] = [o[this.name]];
                    }
                    o[this.name].push(this.value || '');
                } else {
                    o[this.name] = this.value || '';
                }
            });
            return o;
        };
    })(jQuery);

    $('form').submit(function (e) {
        e.preventDefault();
        var data = $('form').serialize(); // 类似get的url拼参数方式，需要转换json用下面
        // var data = $(this).serializeFormJSON();
        console.log(data);

        $.ajax({
            type: "patch",
            url: "/users/repassword",
            cache: false,
            data: data,
            dataType: "json",
            contentType: 'application/x-www-form-urlencoded',
            success: function (data) {
                if (data.code == "0") {
                    // 正确的其他处理...
                    layer.msg(data.msg, {icon: 6});
                } else {
                    // 错误的其他处理...
                    layer.msg(data.msg, {icon: 6});
                }
            },
            error: function (E) {
                console.log(E);
                layer.msg('提交系统失败，请稍后再试', {icon: 6});
            }
        });
    });

    // $(document).ready(function() {

    // });

</script>
</body>
</html>